<template>
  <div class="base-container" id="main">
    <t-form ref="form" :data="queryParams" label-width="80" @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}" @reset="()=>{this.queryParams.pageNum=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="标准名称" name="projectName">
            <t-input
              v-model="queryParams.projectName"
              clearable
              placeholder="请输入标准名称"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="标准性质" name="standardProperty">
            <t-select style="width: 240px" clearable  v-model="queryParams.standardProperty"
                      :options="dict.type.standard_property">
            </t-select>
          </t-form-item>
          <t-form-item label="制定或修订" name="formulateType">
            <t-select style="width: 240px" clearable  v-model="queryParams.formulateType"
                      :options="dict.type.formulate_type">
            </t-select>
          </t-form-item>
          <t-form-item label="主管部门" name="manageDeptId">
            <t-tree-select style="width: 300px" clearable filterable :treeProps="{ keys: { value: 'id' } }"
                           v-model="queryParams.manageDeptId" :data="deptMenuOptions" placeholder="选择主管部门"></t-tree-select>
          </t-form-item>
          <t-form-item label="起草单位" name="draftUnitNames">
            <t-input
              v-model="queryParams.draftUnitNames"
              clearable
              placeholder="请输入起草单位"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="计划完成时间" name="publicDateRange">
            <t-date-range-picker style="width: 280px" :placeholder="['开始时间','结束时间']" v-model="queryParams.publicDateRange"  allow-input clearable/>
          </t-form-item>
          <t-form-item label="有项目支撑" name="projectUp">
            <t-select style="width: 240px" clearable :options="dict.type.yes_or_not" v-model="queryParams.projectUp"></t-select>
          </t-form-item>
          <t-form-item label="有涉及专利" name="patentUp">
            <t-select style="width: 240px" clearable :options="dict.type.yes_or_not" v-model="queryParams.patentUp"></t-select>
          </t-form-item>
            <t-form-item label="标准状态" name="standardStatus">
            <t-select style="width: 240px" clearable  v-model="queryParams.standardStatus"
                      :options="dict.type.standard_status">
            </t-select>
          </t-form-item>
           <t-form-item label="分配状态" name="isAddReview">
            <t-select  style="width: 240px" clearable v-model="queryParams.isAddReview"
                       :options="[{value:'0',label:'未分配'},{value:'1',label:'已分配'}]">
            </t-select>
          </t-form-item>
        <t-form-item label="标委会审批状态" name="xsReviewStatus">
            <t-select style="width: 240px" clearable  v-model="queryParams.xsReviewStatus"
                      :options="dict.type.xs_review_status">
            </t-select>
        </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <t-tabs  @change="(val)=>{queryParams.xsReviewType=val;getList();}" v-model="queryParams.xsReviewType" style="margin-bottom: 10px">
      <t-tab-panel :key="item.id" :value="item.id" v-for="(item) in queryTypeOptions" :label="item.name" :destroyOnHide="false">
      </t-tab-panel>
    </t-tabs>
    <t-table rowKey="index" size="small" :data="data" :columns="columns" hover :pagination="pagination"
             :loading="dataLoading" :sort="sort" :hideSortTips="true" @sort-change="sortChange">
      <template #projectName="{ row }">
        <t-link @click="handleOpenDetail(row)" hover="color" theme="primary">{{ row.projectName }}</t-link>
      </template>
      <template #standardProperty="{ row }">
        {{ row.standardProperty | filterByDict(dict.type.standard_property) }}
      </template>

      <template #formulateType="{ row }">
        {{ row.formulateType | filterByDict(dict.type.formulate_type) }} <span v-if="row.formulateType!=='1'">({{ row.reviseNum }})</span>
      </template>

      <template #draftUnitNames="{ row }">
        <t-tooltip :content="row.draftUnitNames">
          <p style="display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; text-overflow: ellipsis; overflow: hidden;">
            {{row.draftUnitNames || "-"}}
          </p>
        </t-tooltip>
      </template>

      <template #standardStatus="{ row }">
        <t-tag  @click="dialog.header=row.projectName;dialog.standardCategory=row.standardCategory;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.standardStatus, dict.type.standard_status)" variant="light">
          {{ row.standardStatus | filterByDict(dict.type.standard_status) }}
        </t-tag>
      </template>

      <template #projectUp="{ row }">
        {{ row.projectUp === '1'?'是':'否' }}
      </template>
      <template #patentUp="{ row }">
        {{ row.patentUp === '1'?'是':'否' }}
      </template>
        <template #[`isAddReview`]="{ row }">
        <t-tag variant="light" theme="success" v-if="row.isAddReview==='1'">
          已分配
        </t-tag>
        <t-tag  variant="light" theme="warning" v-else>
          未分配
        </t-tag>
      </template>
         <template #xsReviewStatus="{ row }">
            <t-tag v-if="row.xsReviewStatus" @click="dialog.header=row.projectName;dialog.standardCategory=row.standardCategory;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.xsReviewStatus, dict.type.xs_review_status)" variant="light">
              {{ row.xsReviewStatus | filterByDict(dict.type.xs_review_status) }}
            </t-tag>
            <t-tag  class="cursor-pointer" v-else @click="dialog.header=row.projectName;dialog.standardCategory=row.standardCategory;dialog.objId=row.id;dialog.open_approve_list=true" theme="warning" variant="light">未评审</t-tag>
          </template>
      <template #op="{ row }">
        <t-button size="small" @click="handleByDetails(row)" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
        <t-button v-if="row.isAddReview==='0'" theme="danger"  size="small" variant="text"
                @click="dialog.row=row;dialog.open_approve_back=true" 
                  class="t-button-link">
          <t-icon name="rollback" slot="icon" />
          退回
        </t-button>
      </template>
    </t-table>
    <standardDetailDialog :tabDefaultValue="tabDefaultValue"  :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_standard_detail" v-if="dialog.open_standard_detail">
    </standardDetailDialog>
    <approveList :header="dialog.header" :standardCategory="dialog.standardCategory" :obj-id="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approveList>
    <standardDetailDialogOld  :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_standard_detail_old" v-if="dialog.open_standard_detail_old"></standardDetailDialogOld>
    <!-- 建议表 -->
    <suggest-detail-dialog :obj-id="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail_x" v-if="dialog.open_detail_x" ></suggest-detail-dialog>
    <!-- 申报书 -->
    <apply-detail-dialog :obj-id="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail_a" v-if="dialog.open_detail_a" ></apply-detail-dialog>
    <!-- 申报表 -->
      <report-detail-dialog :obj-id="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail_b" v-if="dialog.open_detail_b" ></report-detail-dialog>
    <!-- 报批表 -->
       <submit-detail-dialog :obj-id="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail_c" v-if="dialog.open_detail_c" ></submit-detail-dialog>
         <approve-back  :visible.sync="dialog.open_approve_back"
                   @reload="getList()"
                   :row="dialog.row"
                   v-if="dialog.open_approve_back"></approve-back>
  </div>
</template>

<script>
import standardDetailDialog from "@/pages/bzh/standard/components/standard-detail-dialog.vue";
import standardDetailDialogOld from "@/pages/bzh/standard/components/standard-detail-dialog-old.vue";
import approveList from "@/pages/bzh/approve/components/approve-list.vue";
import applyDetailDialog from "@/pages/bzh/apply/components/apply-detail-dialog.vue";
import suggestDetailDialog from "@/pages/bzh/suggest/components/suggest-detail-dialog.vue";
import reportDetailDialog from "@/pages/bzh/report/components/report-detail-dialog.vue";
import submitDetailDialog from "@/pages/bzh/submit/components/submit-detail-dialog.vue";
import ApproveBack from "./components/approve-back.vue";

export default {
  dicts:["formulate_type","approve_status","standard_status", 'standard_property', 'yes_or_not',"xs_review_status"],
  components: {
    standardDetailDialog,
    approveList,
    standardDetailDialogOld,
    suggestDetailDialog,
    applyDetailDialog,
    reportDetailDialog,
    submitDetailDialog,
    ApproveBack
  },
  data() {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      deptMenuOptions:[],
      queryTypeOptions: [
        {
          id: "0",
          name: '建议表标委会审查',
        },
        {
          id: "1",
          name: '申报书标委会审查',
        },
        {
          id: "2",
          name: '报审表标委会审查',
        },
        {
          id: "3",
          name: '报批表标委会审查',
        }
      ],
      tabDefaultValue:"",
      queryParams:{
        pageNum:1,
        pageSize:10,
        projectName:"",
        formulateType:"",
        publicDateRange: [],
        standardProperty: '',
        completeDate: '',
        startCompleteDate: '',
        endCompleteDate: '',
        patentUp: '',
        projectUp: '',
        standardStatus: '',
        approveStatus: '',
        xsReviewType: "0",
        xsReviewStatus: '',

      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10,20,30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
      dialog:{
        row:{},
        objId: null,
        header:"",
        open_detail: false,
        open_approve_list: false,
        standardCategory: false,
        open_standard_detail: false,
        open_standard_detail_old: false,
        open_detail_x:false,
        open_detail_a:false,
        open_detail_b:false,
        open_detail_c:false,
        open_approve_back:false
      },
      sort:[],
      dataLoading: false,
      columns:[
        {
          colKey: "projectName",
          title: "标准名称",
          align: "center",
          width: 220
        },
        {
          colKey: "systemName",
          title: "标准体系",
          align: "center"
        },
        {
          colKey: "standardProperty",
          title: "标准性质",
          align: "center",
        },
        {
          colKey: "formulateType",
          title: "制定/修订",
          align: "center",
          width: 100
        },
        {
          colKey: "manageDeptName",
          title: "主管部门",
          align: "center",
          width: 180,
        },
        {
          colKey: "draftUnitNames",
          title: "起草单位",
          align: "center",
          width: 180,
        },
        {
          colKey: "completeDate",
          title: "计划完成时间",
          align: "center",
          width: 130,
          sorter: true,
        },
        {
          colKey: "projectUp",
          title: "有项目支撑",
          align: "center",
          width: 100
        },
        {
          colKey: "patentUp",
          title: "有涉及专利",
          align: "center",
          width: 100
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 200
        },
        {
          colKey: "standardStatus",
          title: "标准状态",
          align: "center",
          width: 160,
          fixed: 'right'
        },
        {
          colKey: "isAddReview",
          title: "分配状态",
          align: "center",
          width: 100,
          fixed: 'right',
        },
        {
          colKey: "xsReviewStatus",
          title: "标委会审批状态 ",
          align: "center",
          width: 140,
          fixed: 'right'
        },
      
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120,
          fixed: 'right'
        },
      ],
      data: []
    }
  },
  created() {
    this.getList()
    this.getDeptTreeSelect()
  },
  methods: {
    // 排序
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    // 获取接口数据
    getList(){
      [this.queryParams.startCompleteDate,this.queryParams.endCompleteDate] = this.queryParams.publicDateRange;
      this.dataLoading = true
      return this.$api.bzh.approve.getApproverReviewAllList2(this.queryParams).then(response=>{
        this.pagination.total = response.total
        this.data = response.rows
        this.dataLoading = false
      }).catch(e=>{
        this.dataLoading = false
        this.$message.error(e.toString())
      })
    },
    getDeptTreeSelect(){
      return this.$api.system.dept.treeSelectAllIn().then(response=>{
        this.deptMenuOptions = response.data
      }).catch(e=>{
        this.$message.error(e.toString())
      })
    },
    // 编辑按钮
    update(row){
      this.$router.push({
        path:`/bzh/other/suggest/suggest-apply/${row.id}`,
      });
    },
    // 详情
    handleOpenDetail(row){
      const xsReviewType  = Number(this.queryParams.xsReviewType)
      switch (xsReviewType) {  
      case 0:
        this.tabDefaultValue = "1"
        break;
      case 1:  
        this.tabDefaultValue = "2"
        break;  
      case 2: 
        this.tabDefaultValue = "4"
        break;  
      case 3:  
        this.tabDefaultValue = "5"
        break;  
      default:  
        this.tabDefaultValue = "2"
      }
      this.dialog.header =  row.projectName
      this.dialog.objId =  row.id
      this.dialog.open_standard_detail =  true
    },
    handleByDetails(row){
      this.dialog.header=row.projectName
      this.dialog.objId=row.id
      const xsReviewType  = Number(this.queryParams.xsReviewType)
      switch (xsReviewType) {  
      case 0:
        this.dialog.open_detail_x =true
        break;
      case 1:  
        this.dialog.open_detail_a =true
        break;  
      case 2: 
        this.dialog.open_detail_b =true
        break;  
      case 3:  
        this.dialog.open_detail_b =true
        break;  
      default:  
        this.dialog.open_detail_x =true
      }
    },
  }
}
</script>

<style lang="less" scoped>

</style>

